home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / php / PEAR / CodeGen / ExtensionParser.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  10.9 KB  |  422 lines

  1. <?php
  2. /**
  3.  * Parser for XML based extension desription files
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   Tools and Utilities
  14.  * @package    CodeGen
  15.  * @author     Hartmut Holzgraefe <hartmut@php.net>
  16.  * @copyright  2005 Hartmut Holzgraefe
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id: ExtensionParser.php,v 1.16 2006/06/24 12:37:03 hholzgra Exp $
  19.  * @link       http://pear.php.net/package/CodeGen
  20.  */
  21.  
  22.  
  23. /**
  24.  * includes
  25.  */
  26. require_once "CodeGen/XmlParser.php";
  27. require_once "CodeGen/Tools/Indent.php";
  28.  
  29. /**
  30.  * Parser for XML based extension desription files
  31.  *
  32.  * @category   Tools and Utilities
  33.  * @package    CodeGen
  34.  * @author     Hartmut Holzgraefe <hartmut@php.net>
  35.  * @copyright  2005 Hartmut Holzgraefe
  36.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  37.  * @version    Release: @package_version@
  38.  * @link       http://pear.php.net/package/CodeGen
  39.  */
  40. abstract class CodeGen_ExtensionParser 
  41.     extends CodeGen_XmlParser
  42. {
  43.     /**
  44.      * The extension to parse specs into
  45.      *
  46.      * @access private
  47.      * @var    object
  48.      */
  49.     protected $extension;
  50.     
  51.     /** 
  52.      * Constructor
  53.      *
  54.      * @access public
  55.      * @param  object the extension to parse specs into
  56.      */
  57.     function __construct($extension) 
  58.     {
  59.         parent::__construct();
  60.         $this->extension = $extension;
  61.     }
  62.     
  63.     /**
  64.      * Handle <extension>
  65.      *
  66.      * @access private
  67.      * @param  array    attribute/value pairs
  68.      * @return bool     success status
  69.      */
  70.     function tagstart_extension($attr)
  71.     {
  72.         $err = $this->checkAttributes($attr, array("name", "prefix", "version"));
  73.         if (PEAR::isError($err)) {
  74.             return $err;
  75.         }
  76.                                       
  77.         if (!isset($attr["name"])) {
  78.             return PEAR::raiseError("needed attribute 'name' for <extension> not given");
  79.         }
  80.         $err = $this->extension->setName(trim($attr["name"]));
  81.         if (PEAR::isError($err)) {
  82.             return $err;
  83.         }
  84.  
  85.         if (isset($attr["prefix"])) {
  86.             $err = $this->extension->setPrefix(trim($attr["prefix"]));
  87.             if (PEAR::isError($err)) {
  88.                 return $err;
  89.             }
  90.         }
  91.  
  92.         if (isset($attr["version"])) {
  93.             $err = $this->extension->setVersion($attr["version"]);
  94.             if (PEAR::isError($err)) {
  95.                 return $err;
  96.             }
  97.         } else {
  98.             error_log("Warning: no 'version' attribute given for <extension>, assuming ".$this->extension->version()."\n".
  99.                       "         this may lead to compile errors if your spec file was created for an older version");
  100.         }
  101.  
  102.         return true;
  103.     }
  104.     
  105.     /**
  106.      * Handle <extension><name>
  107.      *
  108.      * @access private
  109.      * @param  array    attribute/value pairs
  110.      * @return bool     success status
  111.      */
  112.     function tagstart_extension_name($attr)
  113.     {
  114.         return PEAR::raiseError("extension <name> tag is no longer supported, use <extension>s 'name=...' attribute instead");
  115.     }
  116.     
  117.     
  118.     /**
  119.      * Handle <extension><summary>
  120.      *
  121.      * @access private
  122.      * @param  array    attribute/value pairs
  123.      * @return bool     success status
  124.      */
  125.     function tagstart_extension_summary($attr)
  126.     {
  127.         return $this->noAttributes($attr);
  128.     }
  129.  
  130.     /**
  131.      * Handle <extension></summary>
  132.      *
  133.      * @access private
  134.      * @param  array    attribute/value pairs
  135.      * @param  array    tag data content
  136.      * @return bool     success status
  137.      */
  138.     function tagend_extension_summary($attr, $data)
  139.     {
  140.         return $this->extension->setSummary(CodeGen_Tools_Indent::linetrim($data));
  141.     }
  142.     
  143.     /**
  144.      * Handle <extension><description>
  145.      *
  146.      * @access private
  147.      * @param  array    attribute/value pairs
  148.      * @return bool     success status
  149.      */
  150.     function tagstart_extension_description($attr)
  151.     {
  152.         return $this->noAttributes($attr);
  153.     }
  154.  
  155.     /**
  156.      * Handle <extension></description>
  157.      *
  158.      * @access private
  159.      * @param  array    attribute/value pairs
  160.      * @param  array    tag data content
  161.      * @return bool     success status
  162.      */
  163.     function tagend_extension_description($attr, $data)
  164.     {
  165.         return $this->extension->setDescription(CodeGen_Tools_Indent::linetrim($data));
  166.     }
  167.  
  168.         
  169.  
  170.  
  171.     
  172.     function tagstart_maintainer($attr)
  173.     {
  174.         $this->pushHelper(new CodeGen_Maintainer);
  175.         return $this->noAttributes($attr);;
  176.     }
  177.     
  178.     function tagstart_maintainer_user($attr)
  179.     {
  180.         return $this->noAttributes($attr);;
  181.     }
  182.  
  183.     function tagend_maintainer_user($attr, $data)
  184.     {
  185.         return $this->helper->setUser(trim($data));
  186.     }
  187.     
  188.     function tagstart_maintainer_name($attr)
  189.     {
  190.         return $this->noAttributes($attr);;
  191.     }
  192.  
  193.     function tagend_maintainer_name($attr, $data)
  194.     {
  195.         return $this->helper->setName(trim($data));
  196.     }
  197.  
  198.     function tagstart_maintainer_email($attr)
  199.     {
  200.         return $this->noAttributes($attr);;
  201.     }
  202.  
  203.     function tagend_maintainer_email($attr, $data)
  204.     {
  205.         return $this->helper->setEmail(trim($data));
  206.     }
  207.  
  208.     function tagstart_maintainer_role($attr)
  209.     {
  210.         return $this->noAttributes($attr);;
  211.     }
  212.  
  213.     function tagend_maintainer_role($attr, $data)
  214.     {
  215.         return $this->helper->setRole(trim($data));
  216.     }
  217.  
  218.     function tagend_maintainer($attr, $data)
  219.     {
  220.         $err = $this->extension->addAuthor($this->helper);
  221.         $this->popHelper();
  222.         return $err;
  223.     }
  224.  
  225.     function tagend_maintainers($attr, $data) 
  226.     {
  227.         return true;
  228.     }
  229.  
  230.     function tagstart_release($attr)
  231.     {
  232.         $this->pushHelper(new CodeGen_Release);
  233.         return $this->noAttributes($attr);;
  234.     }
  235.  
  236.     function tagstart_release_version($attr)
  237.     {
  238.         return $this->noAttributes($attr);;
  239.     }
  240.  
  241.     function tagend_release_version($attr, $data)
  242.     {
  243.         return $this->helper->setVersion(trim($data));
  244.     }
  245.  
  246.     function tagstart_release_date($attr)
  247.     {
  248.         return $this->noAttributes($attr);;
  249.     }
  250.  
  251.     function tagend_release_date($attr, $data)
  252.     {
  253.         return $this->helper->setDate(trim($data));
  254.     }
  255.  
  256.     function tagstart_release_state($attr)
  257.     {
  258.         return $this->noAttributes($attr);;
  259.     }
  260.  
  261.     function tagend_release_state($attr, $data)
  262.     {
  263.         return $this->helper->setState(trim($data));
  264.     }
  265.  
  266.     function tagstart_release_notes($attr)
  267.     {
  268.         return $this->noAttributes($attr);;
  269.     }
  270.  
  271.     function tagend_release_notes($attr, $data)
  272.     {
  273.         return $this->helper->setNotes(CodeGen_Tools_Indent::linetrim($data));
  274.     }
  275.  
  276.     function tagend_release($attr, $data)
  277.     {
  278.         $err = $this->extension->setRelease($this->helper);
  279.         $this->popHelper(new CodeGen_Release);
  280.         return $err;
  281.     }
  282.  
  283.     function tagstart_extension_changelog($attr, $data) 
  284.     {
  285.         $this->verbatim();
  286.         return $this->noAttributes($attr);;
  287.     }
  288.  
  289.     function tagend_extension_changelog($attr, $data) 
  290.     {
  291.         return $this->extension->setChangelog(CodeGen_Tools_Indent::linetrim($data));
  292.     }
  293.  
  294.         
  295.     function tagend_license($attr, $data)
  296.     {
  297.         $license = CodeGen_License::factory(trim($data));
  298.         
  299.         if (PEAR::isError($license)) {
  300.             return $license;
  301.         }
  302.         
  303.         return $this->extension->setLicense($license);
  304.     }
  305.  
  306.     function tagend_extension_code($attr, $data) {
  307.         $err = $this->checkAttributes($attr, array("role", "position"));
  308.         if (PEAR::isError($err)) {
  309.             return $err;
  310.         }
  311.                                       
  312.         $role     = isset($attr["role"])     ? $attr["role"]     : "code";
  313.         $position = isset($attr["position"]) ? $attr["position"] : "bottom";
  314.  
  315.         if (isset($attr["src"])) {
  316.             return $this->extension->addCode($role, $position, CodeGen_Tools_Indent::linetrim(file_get_contents($attr["src"])));
  317.         } else {
  318.             return $this->extension->addCode($role, $position, CodeGen_Tools_Indent::linetrim($data));
  319.         }
  320.     }
  321.  
  322.  
  323.     function tagstart_deps($attr)
  324.     {
  325.         $err = $this->checkAttributes($attr, array("platform","language"));
  326.         if (PEAR::isError($err)) {
  327.             return $err;
  328.         }
  329.                                       
  330.         if (isset($attr["platform"])) {
  331.             $err = $this->extension->setPlatform($attr["platform"]);
  332.             if (PEAR::isError($err)) {
  333.                 return $err;
  334.             }
  335.         }
  336.  
  337.         if (isset($attr["language"])) {
  338.             $err = $this->extension->setLanguage($attr["language"]);
  339.             if (PEAR::isError($err)) {
  340.                 return $err;
  341.             }
  342.         }
  343.  
  344.     }
  345.  
  346.     function tagstart_deps_file($attr) 
  347.     {
  348.         $err = $this->checkAttributes($attr, array("name", "dir"));
  349.         if (PEAR::isError($err)) {
  350.             return $err;
  351.         }
  352.                                       
  353.         if (!isset($attr['name'])) {
  354.             return PEAR::raiseError("name attribut for file missing");
  355.         }
  356.  
  357.         if (isset($attr["dir"])) {
  358.             return $this->extension->addSourceFile($attr['name'], $attr['dir']);
  359.         } else {
  360.             return $this->extension->addSourceFile($attr['name']);
  361.         }
  362.     }
  363.         
  364.     function tagstart_deps_lib($attr)
  365.     {
  366.         $err = $this->checkAttributes($attr, array("name", "platform", "function"));
  367.         if (PEAR::isError($err)) {
  368.             return $err;
  369.         }
  370.                                       
  371.         if (!isset($attr['name'])) {
  372.             return PEAR::raiseError("name attribut for lib missing");
  373.         }
  374.  
  375.         // TODO need to use addLibs(), libs[] is protected
  376.         $this->extension->libs[$attr['name']] = $attr;
  377.         if (isset($attr['platform'])) {
  378.             $platform = new CodeGen_Tools_Platform($attr["platform"]);
  379.         } else {
  380.             $platform = new CodeGen_Tools_Platform("all");
  381.         }
  382.  
  383.         if (PEAR::isError($platform)) {
  384.             return $platform;
  385.         }
  386.  
  387.         $this->extension->libs[$attr['name']]['platform'] = $platform;
  388.         return true;
  389.     }
  390.  
  391.     function tagstart_deps_header($attr)
  392.     {
  393.         $err = $this->checkAttributes($attr, array("name", "prepend", "path"));
  394.         if (PEAR::isError($err)) {
  395.             return $err;
  396.         }
  397.                                       
  398.         // TODO check name
  399.         $header = new CodeGen_Dependency_Header($attr["name"]);
  400.  
  401.         if (isset($attr['path'])) {
  402.             $header->setPath($attr["path"]);
  403.         }
  404.  
  405.         if (isset($attr['prepend'])) {
  406.             $header->setPrepend($attr["prepend"]);
  407.         }
  408.  
  409.         $this->extension->addHeader($header);
  410.     }
  411. }
  412.  
  413.  
  414. /*
  415.  * Local variables:
  416.  * tab-width: 4
  417.  * c-basic-offset: 4
  418.  * indent-tabs-mode:nil
  419.  * End:
  420.  */
  421. ?>
  422.